<section class="page-hd">
    <header>
        <p class="title-description title-top">
            类型列表
        </p>
    </header>
    <hr>
</section>
<form method="get" action="">
    <div class="row">
        <div class="col-xs-2">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="编号" name="id" value="{$Request.param.id}">
            </div>
        </div>
        <div class="col-xs-2">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="类型名称" name="typeName"
                       value="{$Request.param.typeName}">
            </div>
        </div>

        <div class="col-xs-1">
            <div class="form-group">
                <button type="submit" class="btn btn-primary radius">搜索</button>
            </div>
        </div>
    </div>
</form>

<table class="table table-bordered">
    <colgroup>
        <col width="40"/>
        <col width="120"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
    </colgroup>
    <thead>
    <tr>
        <th>编号</th>
        <th>类型名称</th>
        <th>排序</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {if condition="!empty($model)"}
    {volist name='$model' id='val' key='k'}
    <tr class="cen">
        <td>{$val.id}</td>
        <td>{$val.typeName}</td>
        <td>{$val.sort}</td>
        <td>{if condition="$val.state == 0"}允许{else/}禁止{/if}</td>
        <td>
            <a title="编辑" class="mr-5" href='{:url("type_detail",["id"=>$val.id])}'>编辑</a>
            <a title="删除" class="del" data-id="{$val.id}">删除</a>
        </td>
    </tr>
    {/volist}
    {/if}
    </tbody>
</table>
<div class="panel panel-default">
    <div class="panel-bd">
        <div class="pagination">
            {$model->render()}
        </div>
    </div>
</div>
<script>
    $('body').on('click', '.del', function () {
        var id = $(this).attr('data-id');
        Ajax("{:url('type_del')}", {id: id});
    });
    function Ajax(url, data) {
        $.ajax({
            url: url,
            cache: false,
            dataType: 'json',
            data: data,
            type: 'post',
        }).done(function (res) {
            if (res.code == 200) {
                layer.alert(res.msg, function () {
                    location.reload();
                });
            } else {
                layer.alert(res.msg);
            }
        }).fail(function (e) {
            layer.alert(e);
        });
    }
</script>